package com.id.supaclean

import android.app.Application
import android.content.Context
import android.util.Log
import com.event.sdk.EventSDK
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.initialize
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.id.supaclean.utils.Events
import com.id.supaclean.utils.FirebaseEventsService
import com.id.supaclean.utils.MetricaEventsService
import com.id.supaclean.utils.getAvailMemory
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesConfiguration
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.random.Random

/**
 * Created by YiGo on 2022/6/15.
 */
class MyApplication : Application() {
    companion object {
        lateinit var appContext: Context
    }

    override fun onCreate() {
        super.onCreate()
        appContext = applicationContext
        MMKV.initialize(appContext)
        Firebase.initialize(this)
        Firebase.remoteConfig.fetchAndActivate()
        Events.initialize(
            FirebaseEventsService(this),
            MetricaEventsService(this, "b3a1486d-6a7b-46ad-926b-3114f34cb13d")
        )
        Purchases.configure(
            PurchasesConfiguration.Builder(this, "goog_cZJFNSeCgRUQrrxXuFgyESAfhle")
                .observerMode(false)
                .appUserID(null)
                .build()
        )
        EventSDK.init(
            this,
            "api.get-supaclean.com",
            "eyJhbGciOiJSUzI1NiIsImtpZCI6ImFoYzZ6c3I5azIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiIyMzA2M2VmOC0yYWE2LTRmYzctOGI5MS1iZDc1ZmE0Y2ZkNGIiLCJpYXQiOjE2NTY1NTk5OTMsImlzcyI6ImFwcGZsb3cuYWkiLCJzdWIiOiJjMzZmNzk5ZC1lMzNmLTRiMDUtOGZiZi1mNDczMzNlNWVjZTUiLCJ0eXBlIjoiYXBwIn0.pIwMTf-c0mNRAHID1jegLB-h9S6c8FWBLSAa_H31LhgLax5JLLutvSD9-fzemSymSyVtnYOv94rolUmevHSZ35N_roIL3lJZyADtXzq2K2aYWj_dwHKkTE5DkImq6FOM-RuvfUKG1yGm2L31MNZLVubURFcGMIKbGbAbrx6bT1vkIXDBBhLxX7Ah_24qIf_5rW8r73FGhgLh02ALfHhdPqw7Wgksnw_O4hbMGM-8inMTupaDvFdJOOYWOo7TxA_wCuzcUCgvDpV9UZdPb3FV4CEsbOIfbC-ABCbn930KosCwryvUWSCr1uWQ1Zigi4Rhk92kdEwS1jQE0DpTk0VIsw"
        )

//        Firebase.remoteConfig.getString("country")

    }
}

val DataStore get() = MMKV.defaultMMKV()